package com.xc.common.object;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import org.apache.commons.beanutils.Converter;

public class LocalDateConverter implements Converter {
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public LocalDate convert(Class aClass, Object o) {
        if(o == null)
            return null;
        
        String str = (String) o;
        if(str.trim().equals(""))
            return null;
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        return LocalDate.parse(str,formatter);
    }

    public static void main(String[] args) {
        String str ="2020-09-16 17:39:25";
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        System.out.println(LocalDate.parse(str,formatter));
    }
}
